package com.ideabove.custom;

import com.ideabove.util.img.BitmapDownloaderTask;
import com.ideabove.util.img.ImageLoader;

import android.content.Context;
import android.graphics.PorterDuff.Mode;
import android.util.AttributeSet;
import android.util.Log;

import android.widget.ImageView;

public class MyCropImageView extends ImageView {
	String imgUrl = null;
	
	public MyCropImageView(Context a_context) {		
		super(a_context);
	}
	
	public MyCropImageView(Context a_context, AttributeSet a_attributeSet) {		
		super(a_context, a_attributeSet);		
	}
	
	public void setImageUrl(String imgUrl){
		this.imgUrl = imgUrl;		
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
//		if(imgUrl != null){			
//			ImageLoader.downloadAndCrop(imgUrl, this, BitmapDownloaderTask.CROP_CENTER);
//			this.setColorFilter(0x662b2b2b,Mode.SRC_OVER);
//			imgUrl = null;
//		}
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	@Override
	protected void onAttachedToWindow() {
		// TODO Auto-generated method stub
		ImageLoader.downloadAndCrop(imgUrl, this, BitmapDownloaderTask.CROP_CENTER);
//		this.setColorFilter(0x662b2b2b,Mode.SRC_OVER);
		super.onAttachedToWindow();
	}

	@Override
	public void onFinishTemporaryDetach() {
		// TODO Auto-generated method stub
		ImageLoader.downloadAndCrop(imgUrl, this, BitmapDownloaderTask.CROP_CENTER);
//		this.setColorFilter(0x662b2b2b,Mode.SRC_OVER);
		super.onFinishTemporaryDetach();
	}

    
    
}
